QuickJs support ESM and add engine->loadFile #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
使QuickJS可以正常使用ESM的import和export机制。默认的JS_EVAL_GLOBAL不支持ESM,此处修改为JS_EVAL_MODULE,并加载了qjs-libc默认提供的es6 module loader. 经过测试可以完全正常工作。
其次,JS_EVAL_MODULE的行为与JS_EVAL_GLOBAL不同。JS_EVAL_GLOBAL在执行多行JS代码时,会将最后一行代码的返回值作为整个eval调用的返回值,而JS_EVAL_MODULE不会这样。这个也可以理解,因为module是针对文件调用而设计的。
(同样的,python backend的eval和文件加载也具有和上述完全一样的行为)
因此,为了解决这两种 读取文件执行 与 普通eval 语义不同的问题,又联想到 #89 issue,为各引擎增加了一个loadFile函数,针对loadFile的特殊情况进行处理,与普通的eval分开。
不需要特殊处理的引擎的loadFile将读取文件后直接调用eval。